/**
 * LeetCode226：翻转二叉树
 * 给定一个二叉树，翻转二叉树的左右节点
 */

function TreeNode(val){
    this.val = val;
    this.left = this.right = null;
}

/**
 *
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var invertTree = function (root){
    if (!root){ return null; }
    return {
        val: root.val,
        left:invertTree(root.right),
        right:invertTree(root.left)
    }
};

//时间复杂度：O(n)
//空间复杂度：O(n)